package shake.filter;

import java.io.IOException;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class FilterChainImpl implements javax.servlet.FilterChain {

	List<Filter> filter;
	int pos = 0;
	FilterChain chain;

	public FilterChainImpl(List<Filter> filter, FilterChain chain) {
		super();
		this.filter = filter;
		this.chain = chain;
	}

	public void doFilter(ServletRequest request, ServletResponse response)
			throws IOException, ServletException {
		if (pos < filter.size()) {
			pos++;
			filter.get(pos - 1).doFilter(request, response, this);
		} else {
			chain.doFilter(request, response);
		}

	}

}
